package com.example.plane.GameView;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import com.example.plane.GameActivity;
import com.example.plane.MainActivity;
public class background  {

        public int[] currX=new int[2];
        public int[] currY=new int[2];
        public  int[] bgwidth=new int[2];
        public  int[] bgheight=new int[2];
        public  float[] scaleWidth=new float[2];
        public  float[] scaleHeight=new float[2];
        public  Paint p = new Paint();//拿到画笔
        public  int fristpass=2;
        public Bitmap[] bitmap=new Bitmap[fristpass];
    public background( )
    {

    }
        public void  initView()
        {
                for (int i = 0; i < fristpass; i++) {
                        bitmap[i] = MainActivity.bitmap[0];
                        bgwidth[i] = bitmap[i].getWidth();
                        bgheight[i] = bitmap[i].getHeight();
                        scaleWidth[i] = ((float)GameActivity.Scrrenwidth)/ bgwidth[i];//计算宽度的缩放比例
                        scaleHeight[i] = ((float) GameActivity.Screenheight)/ bgheight[i];//计算高度的缩放比例
                        Matrix matrix = new Matrix();//矩阵类用于图像坐标的转换，以及旋转，缩放等特殊操作。
                        matrix.postScale(scaleWidth[i], scaleHeight[i]);//设置缩放
                        //如果将实例化在外面即不释放内存，该对象会一直缩放
                        bitmap[i] = Bitmap.createBitmap(bitmap[i], 0, 0, bgwidth[i], bgheight[i], matrix, false);//创建一个缩放后的图片
                }
                currX[0]=0;
                currY[0]=0;
                currX[1]=0;;
                currY[1]=-bitmap[1].getHeight();
        }

        public void bgpaint()
        {
            p.setDither(true);
        }
        public void doDraw(Canvas canvas )
        {
               bgpaint();
                for(int i=0;i<fristpass;i++) {
                        canvas.drawBitmap(bitmap[i],currX[i], currY[i], p);
                }
        }

        public void bglogic()
        {
               currY[0]=currY[0]+10;//图片以每帧二十个位置的速度下移
               currY[1]=currY[1]+10;;
               for(int i=0;i<fristpass;i++)
               {
            if (currY[i] >= bitmap[i].getHeight()) {//如如果到达底部，设置其到最顶部
                currY[i] = -bitmap[i].getHeight();
               }
               }
    }


        }
